﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Telerik.Web.UI;

public partial class main_dataQuery_HJQX : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        RadWindowManager1.OffsetElementID = LinkButton1.ClientID;
        RadWindowManager1.Windows[0].OffsetElementID = LinkButton1.ClientID;
        RadWindowManager1.Windows[0].OpenerElementID = LinkButton1.ClientID;
        if (!IsPostBack)
        {
            //所有空间可视值的初始化
            RadGrid1.Visible = false;
            LinkButton4.Visible = false;
            //lable控件默认值赋值
            Label_LineName.Text = "练塘-漕泾 >> ";
            Label_TowerName.Text = "C1+1";
            HiddenField_LineName.Value = "练塘-漕泾";
            HiddenField_TowerName.Value = "C1+1";

            
            LineDAOs lineDAOs = LineDAOs.getInstance();
            TowerDAOs towerDAOs = TowerDAOs.getInstance();
            List<String> lineNameList = lineDAOs.getLineNameList();
            for (int i = 0; i < lineNameList.Count; i++)
            {
                RadTreeNode lnode = new RadTreeNode(lineNameList[i]);
                List<String> towerNameList = towerDAOs.getcorrespondingTowerNameList_HJQX(lineNameList[i]);
                for (int j = 0; j < towerNameList.Count; j++)
                {
                    RadTreeNode tnode = new RadTreeNode(towerNameList[j]);
                    lnode.Nodes.Add(tnode);
                }
                RadTreeView1.Nodes.Add(lnode);
            }
        }
    }


    protected void LinkButton1_Click(object sender, EventArgs e)
    {
      
    }

    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        UpdateGridView();

        Label_LineName.Text = HiddenField_LineName.Value + " >> ";
        Label_TowerName.Text = HiddenField_TowerName.Value;

        RadGrid1.Visible = true;
        LinkButton4.Visible = true;
    }

    protected void RadGrid1_PageIndexChanged(object source, GridPageChangedEventArgs e)
    {
        RadGrid1.CurrentPageIndex = e.NewPageIndex;
        UpdateGridView();
    }
    protected void RadGrid1_PageSizeChanged(object source, GridPageSizeChangedEventArgs e)
    {
        UpdateGridView();
    }
    //单击显示图形按钮时发生
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        RadGrid1.Visible = false;
        LinkButton4.Visible = false;
    }
    protected void UpdateGridView()
    {

        DataTable dataTable;
        TowerDAOs towerDAOs = TowerDAOs.getInstance();
        dataTable = towerDAOs.getDTDataQueryHJQX(HiddenField_LineName.Value, HiddenField_TowerName.Value, RadDatePicker1.SelectedDate.Value, RadDatePicker2.SelectedDate.Value);
        //this.ViewState["vsTable"] = dataTable;
        RadGrid1.DataSource = dataTable;
        RadGrid1.DataBind();
    }
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            for (int i = 0; i < RadGrid1.Columns.Count; i++)
            {
                if (RadGrid1.Columns[i].UniqueName.EndsWith("ABNORMAL"))
                {
                    if (Int64.Parse(item[RadGrid1.Columns[i].UniqueName].Text) > 0)
                    {
                        String s = RadGrid1.Columns[i].UniqueName.Substring(0, RadGrid1.Columns[i].UniqueName.Length - 9);
                        ((GridDataItem)e.Item)[s].ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
        }
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        if (RadGrid1.Visible == true)
        {
            RadGrid1.ExportSettings.ExportOnlyData = false;
            RadGrid1.ExportSettings.IgnorePaging = true;

            UpdateGridView();
            for (int i = 0; i < RadGrid1.Columns.Count; i++)
            {
                if (RadGrid1.Columns[i].UniqueName.EndsWith("ABNORMAL"))
                {
                    RadGrid1.MasterTableView.GetColumn(RadGrid1.Columns[i].UniqueName).Visible = false;
                }
            }
            RadGrid1.MasterTableView.ExportToCSV();
        }
    }
}
